package org.zhadoop.stream.cql.semanticanalyzer.parser.context;

import java.util.List;

import org.zhadoop.stream.cql.DriverContext;
import org.zhadoop.stream.cql.exception.CQLException;
import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.hooks.SemanticAnalyzeHook;
import org.zhadoop.stream.cql.semanticanalyzer.OrderByClauseAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.SemanticAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextwalker.ParseContextWalker;
import org.zhadoop.stream.cql.tasks.Task;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

/**
 * orderby 子句语法分析内容
 * 
 * @author zwd
 *
 */
public class OrderbyClauseContext extends ParseContext {

	private List<ColumnNameOrderContext> orderColumns;

	public OrderbyClauseContext() {
		orderColumns = Lists.newArrayList();
	}

	@Override
	public String toString() {
		return "ORDER BY " + Joiner.on(", ").join(orderColumns);
	}

	@Override
	public Task createTask(DriverContext driverContext, List<SemanticAnalyzeHook> analyzeHooks) throws CQLException {
		return null;
	}

	@Override
	public SemanticAnalyzer createAnalyzer() throws SemanticAnalyzerException {
		return new OrderByClauseAnalyzer(this);
	}

	@Override
	protected void walkChild(ParseContextWalker walker) {
		for (ColumnNameOrderContext col : orderColumns) {
			walkExpression(walker, col);
		}
	}

	public List<ColumnNameOrderContext> getOrderColumns() {
		return orderColumns;
	}

	public void setOrderColumns(List<ColumnNameOrderContext> orderColumns) {
		this.orderColumns = orderColumns;
	}
}
